#include <interface\color.h>

#include <cstdio>

color::color(){
        for( int i = 0; i < 4; i++ ){
            iColor[i] = 0;
            fColor[i] = 0;
        }
}
color::color(color_index idx){
    setColorid(idx);
}
color::color(int r,int g,int b,int a){
    iColor[0] = r;
    iColor[1] = g;
    iColor[2] = b;
    iColor[3] = a;
    itof();
}
color::color(float r,float g,float b,float a){
    fColor[0] = r;
    fColor[1] = g;
    fColor[2] = b;
    fColor[3] = a;
    ftoi();
}
color::~color(){
    printf("Color deletion\n");
}

void color::setColorid(color_index idx){
    for( int i = 0; i < 4; i++ ){
        iColor[i] = 0;
        fColor[i] = 0;
    }
    color_index col = idx & COLOR_MASK;
    if( col == col_white )          { iColor[0] = 0xff; iColor[1] = 0xff; iColor[2] = 0xff; }
    else if( col == col_li_grey )   { iColor[0] = 0xcc; iColor[1] = 0xcc; iColor[2] = 0xcc; }
    else if( col == col_md_grey )   { iColor[0] = 0x99; iColor[1] = 0x99; iColor[2] = 0x99; }
    else if( col == col_dk_grey )   { iColor[0] = 0x66; iColor[1] = 0x66; iColor[2] = 0x66; }
    else if( col == col_li_blue )   { iColor[0] = 0x00; iColor[1] = 0x00; iColor[2] = 0xcc; }
    else if( col == col_md_blue )   { iColor[0] = 0x00; iColor[1] = 0x00; iColor[2] = 0x99; }
    else if( col == col_dk_blue )   { iColor[0] = 0x00; iColor[1] = 0x00; iColor[2] = 0x66; }
    else if( col == col_li_red )    { iColor[0] = 0xcc; iColor[1] = 0x00; iColor[2] = 0x00; }
    else if( col == col_md_red )    { iColor[0] = 0x99; iColor[1] = 0x00; iColor[2] = 0x00; }
    else if( col == col_dk_red )    { iColor[0] = 0x66; iColor[1] = 0x00; iColor[2] = 0x00; }
    else if( col == col_li_green )  { iColor[0] = 0x00; iColor[1] = 0xcc; iColor[2] = 0x00; }
    else if( col == col_md_green )  { iColor[0] = 0x00; iColor[1] = 0x99; iColor[2] = 0x00; }
    else if( col == col_dk_green )  { iColor[0] = 0x00; iColor[1] = 0x66; iColor[2] = 0x00; }
    else if( col == col_li_fushia ) { iColor[0] = 0xcc; iColor[1] = 0x00; iColor[2] = 0xcc; }
    else if( col == col_md_fushia ) { iColor[0] = 0x99; iColor[1] = 0x00; iColor[2] = 0x99; }
    else if( col == col_dk_fushia ) { iColor[0] = 0x66; iColor[1] = 0x00; iColor[2] = 0x66; }
    else /*  col == col_black    */ { iColor[0] = 0x00; iColor[1] = 0x00; iColor[2] = 0x00; }
    itof();
}

void color::setColor3i(int r,int g,int b){
    iColor[0] = r;
    iColor[1] = g;
    iColor[2] = b;
    itof();
}
void color::setColor4i(int r,int g,int b,int a){
    iColor[0] = r;
    iColor[1] = g;
    iColor[2] = b;
    iColor[3] = a;
    itof();
}
void color::setColor3f(float r,float g,float b){
    fColor[0] = r;
    fColor[1] = g;
    fColor[2] = b;
    ftoi();
}
void color::setColor4f(float r,float g,float b,float a){
    fColor[0] = r;
    fColor[1] = g;
    fColor[2] = b;
    fColor[3] = a;
    ftoi();
}
void color::itof(){
    for( int i = 0; i < 4; i++ ){
        fColor[i] = ((float)iColor[i]/(float)255);
    }
}
void color::ftoi(){
    for( int i = 0; i < 4; i++ ){
        iColor[i] = (int)(fColor[i]*(float)255);
    }
}

int* color::getColorVi(){
    return iColor;
}
float* color::getColorVf(){
    //printf("getting %f %f %f\n",fColor[0],fColor[1],fColor[2]);
    return fColor;
}

int color::getRiVal(){
    return iColor[0];
}
int color::getGiVal(){
    return iColor[1];
}
int color::getBiVal(){
    return iColor[2];
}
int color::getAiVal(){
    return iColor[3];
}

float color::getRfVal(){
    return fColor[0];
}
float color::getGfVal(){
    return fColor[1];
}
float color::getBfVal(){
    return fColor[2];
}
float color::getAfVal(){
    return fColor[3];
}
